[nrowAeq, ncolAeq] = size(nAeq);

% check Aeq has full row rank
if rank(nAeq)==nrowAeq
    fullRowRank=true;
end
%-------------------------------

if fullRowRank == true    
    tic;
    %------------------------------M, r, y
    [nrowAeq, ncolAeq] = size(nAeq);
    
    % generate random n x n non-singular matrix M
    M = randi([1,50],ncolAeq);
    
    while det(M)==0
        M = randi([1,50],ncolAeq);
    end
    
    % generate random n x 1 vector r
    r = randi([1,50],ncolAeq,1);
    
    while nbeq + nAeq * r == 0
        r = randi([1,50],ncolAeq,1);
    end
    
    % generate random integer between 1 and 1000
    y = round(rand(1)*999)+1;
    
    cT = y * M' * nC;           % c' = yM'c
%     cT = y * nC;
    
    % -----------------------Q, A', b'
    % generate m x m non-singular matrix Q (deteminant =/= 0)
    % Q=rand(nrowAeq);
    Q = randi([1,50],nrowAeq);
    
    while det(Q)==0
        Q = randi([1,50],nrowAeq);
    end
    
    AeqT = Q * nAeq * M;                    % A' = QAM
    beqT = Q * (nbeq + (nAeq * r));         % b' = Q(b + Ar)
    
%     AeqT = Q * nAeq;                      % A' = QA
%     beqT = Q * nbeq;                      % b' = Qb
    
    %-----------------------------
    [nrowAeqT, ncolAeqT] = size(AeqT);
    positiveValue = nrowAeqT;    % find the positive value of nbeq from end of the vector
    allZero = true;             % determine nbeq is all zero
    
    % find the positive value of nbeq from end of the vector
    while positiveValue ~= 0
        if beqT(positiveValue) ~= 0
%         if nbeq(positiveValue) ~= 0
            allZero = false;            % found & exit loop
            break;
        end
        positiveValue = positiveValue - 1;
    end
    
    % generate a random n x m lamda
    L =randi([1,50],ncolAeqT,nrowAeqT);
    sum = 0;      % sum of each row
    
    Br = nA * r;              % Br
    % change content of L in order to cause L * b'(beqT) = B(nA)r
    if allZero == false
        if positiveValue == 1
            % change first column of L to zero
            for ii=1:1:ncolAeqT                  % row
                if positiveValue == 1
                    L(ii, 1) = 0;
                end
            end
        else
            for ii=1:1:ncolAeqT                  % row
                for jj=1:1:(positiveValue-1)     % col
%                     sum = sum + (L(ii,jj) * beqT(jj));
                    sum = sum + (L(ii,jj) * nbeq(jj));
                end
%                 L(ii, positiveValue) = (Br(ii) - sum) / beqT(positiveValue);
                    L(ii, positiveValue) = 0-sum / nbeq(positiveValue);
                sum = 0;
            end
        end
    end
    
    AT = (nA * M) - (L * AeqT);         % B' = BM - LQAM => BM-LA' =>(A' = AeqT)
    bT = (nA * r) - (L * beqT);         % 0 = Br - L(Q(b+Ar)) =>(Q(b+Ar) = beqT)

%     AT = (nA - (L * nAeq));               % B' = (B - LA)
%     bT = -1 * (L * nbeq);
    
    % display transform Time
    toc
end

tic;
[y,fval,exitflag,output,lambda] = linprog(cT,AT,nb,AeqT,beqT);
toc

y=(y*100)/100
x2 = (M * y) - r;
n=1;
nX2=[];
temp=0;

for ii=1:1:cRow
    if ii == cVariable(n)
        if x2(ii) < 0.0001
            temp = 0;
        else
            temp = (x2(ii)*100)/100;
        end
        nX2{n,1} = ['x' num2str(ii) ' = ' num2str(temp)];
        n = n + 1;
    end    
end
nX2